package atpa.partial;

public class StivaT {

    int tab[];
    int varf = 0;

    public StivaT(int dim) {
        this.tab = new int[dim];
    }

    public boolean isEmpty() {
        return (varf == 0);
    }

    public boolean isFull() {
        return (varf == tab.length);
    }

    public void push(int val) {
        if (!isFull()) {
            tab[varf++] = val;
        } else {
            System.out.println("ERROR: Stack full");
        }
    }

    public int pop() {
        if (!isEmpty()) {
            return tab[--varf];
        }else{
            System.out.println("ERROR: Stack empty");
            return -1;
        }
    }

    public int peek() {
        if (!isEmpty()) {
            return tab[varf - 1];
        }else{
            System.out.println("ERROR: Stack empty");
            return -1;
        }
    }

    public void show() {
        if (varf==0){
            System.out.println("ERROR: Stack empty");
            return;
        }
        for (int i = varf - 1; i >= 0; i--) {
            System.out.println(tab[i]);
        }
        System.out.println("-----------");
    }
}
